package com.kyang.musiconline.model;

import lombok.Data;
import org.springframework.jdbc.core.RowMapper;

import java.io.Serial;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

/**
 * @author kyang
 */
@Data
public class User implements Serializable, RowMapper<User> {
    @Serial
    private static final long serialVersionUID = -7284934411071940570L;
    private String id;
    private String account;
    private String nickName;
    private String password;
    private Integer sex;
    private Integer age;
    private String phone;
    private String address;
    private String avatarUrl;
    private Date createDate;
    private Date updateDate;
    private Boolean isAdmin = false;
    private Boolean isDelete = false;

    @Override
    public User mapRow(ResultSet rs, int rowNum) throws SQLException {
        User user = new User();
        user.setId(rs.getString("id"));
        user.setAccount(rs.getString("account"));
        user.setNickName(rs.getString("nickname"));
        user.setPassword(rs.getString("password"));
        user.setSex(rs.getInt("sex"));
        user.setAge(rs.getInt("age"));
        user.setAddress(rs.getString("address"));
        user.setPhone(rs.getString("phone"));
        user.setAddress(rs.getString("address"));
        user.setAvatarUrl(rs.getString("avatar_url"));
        return user;
    }

    public Object[] convertObjects() {
        Object[] objects = new Object[13];
        objects[0] = this.id;
        objects[1] = this.account;
        objects[2] = this.nickName;
        objects[3] = this.password;
        objects[4] = this.sex;
        objects[5] = this.age;
        objects[6] = this.phone;
        objects[7] = this.address;
        objects[8] = this.avatarUrl;
        objects[9] = this.createDate;
        objects[10] = this.updateDate;
        objects[11] = this.isAdmin;
        objects[12] = this.isDelete;
        return objects;
    }
}
